package com.google.code.jtasks.model;

import java.io.Serializable;


/**
 * Models the unique identifier of each {@link IMappedTask} in a specific task system.
 */
public final class TaskId implements Serializable
{
	private static final long serialVersionUID = 1L;

	private final String idString;

	/**
	 * Constructs a new {@link TaskId} instance.
	 * 
	 * @param idString
	 *            The case-sensitive text representation of the task identifier. Please note that any leading
	 *            or trailing whitespace will be trimmed from this {@link String}.
	 */
	public TaskId(String idString)
	{
		if (idString == null || idString.trim().length() <= 0)
			throw new IllegalArgumentException("Invalid ID string: " + idString);

		this.idString = idString.trim();
	}

	/**
	 * Returns the case-sensitive text representation of the task identifier.
	 * 
	 * @return the case-sensitive text representation of the task identifier
	 */
	public String getIdString()
	{
		return idString;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (obj == null || !(obj instanceof TaskId))
			return super.equals(obj);
		TaskId other = (TaskId) obj;

		return idString.equals(other.idString);
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		return idString.hashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		StringBuilder debugText = new StringBuilder();
		debugText.append(this.getClass().getSimpleName());
		debugText.append("[");
		debugText.append("idString=");
		debugText.append(idString);
		debugText.append("]");
		return debugText.toString();
	}
}
